package com.example.netty.netty.HTTPExample;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.ssl.*;

import javax.net.ssl.SSLContext;

public class NettyServer {
    public static void main(String[] args) throws InterruptedException {
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        try {
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup,workerGroup)
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new ServerInitializer());

            //有些端口访问不了，可能被占用了
            ChannelFuture channelFuture = serverBootstrap.bind(6969).sync();
            channelFuture.channel().closeFuture().sync();
        }finally {
            //出现异常后优雅关闭group
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }

    }
}
